package com.soft.javase.day10.review.reduce;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/5/4
 */
public class ReduceDemo {
    public static void main(String[] args) {

        System.out.println("求一组数据中的最大值");
        Integer max = Stream.of(22, 33, 11, 44, 55).reduce(Integer::max).orElse(0);
        System.out.println(max);

        System.out.println("求一组数据的和");
        Integer sum = Stream.of(30, 20, 11, 55, 77).reduce(Integer::sum).orElse(0);
        System.out.println(sum);

        System.out.println("求一组数据的拼接");
        String s = Stream.of("java", "python", "c++").reduce(String::concat).orElse("");
        System.out.println(s);

        System.out.println("求一组员工的工资总和");
        List<Employee> list = new ArrayList<>();
        list.add(new Employee("张三",5000.0));
        list.add(new Employee("李四",6000.0));
        list.add(new Employee("王五",7000.0));
        list.add(new Employee("赵六",8000.0));
        Double salarySum = list.stream().map(Employee::getSalary).reduce(Double::sum).orElse(0.0);
        System.out.println(salarySum);

    }
}
